template <typename Ty> fcf::NTest::LogWriter&
operator<<(
const Ty& a_value)
template <typename Ty> fcf::NTest::LogWriter&
operator<<(
std::ostream& (*a_manipulator)(std::ostream&))
Class: fcf::NTest::LogWriter
Package: fcfTest
File: test.hpp
Available from version: 1.1.1
Appends a value of any type to the internal log buffer using the standard stream insertion operator.
This template method allows the fcf::NTest::LogWriter to behave like a standard std::ostream. It captures the provided value and stores it in an internal std::stringstream buffer.
The actual writing to the final output targets (like std::cout or a file) is deferred until the fcf::NTest::LogWriter object is destroyed (RAII principle) or the buffer is explicitly flushed.
The value a_value must support the operator<< for the target stream type.
Template arguments
Ty
- The type of the value to be appended to the log.
Arguments
const Ty& a_value
- The value to be inserted into the log stream.
Result
fcf::NTest::LogWriter&
- A reference to the current fcf::NTest::LogWriter instance, enabling method chaining (e.g., writer << a << b;).
Example: Chaining multiple types in a single log statement
Demonstrating how to use the stream operator to log different data types in a single line using method chaining.
#define FCF_TEST_IMPLEMENTATION
#include <fcfTest/test.hpp>
#include <string>
#include <vector>
FCF_TEST_DECLARE("LogDemo", "Chaining", "MultiTypeLog") {
int userId = 42;
std::string userName = "JohnDoe";
double score = 95.5;
// 1. Using the operator<< to chain different types.
// The LogWriter object is created by fcf::NTest::inf().
// The values are buffered and printed when the statement ends.
fcf::NTest::inf() << "User: " << userId << " (" << userName << ") | Score: " << score << std::endl;
// 2. Using stream manipulators (like std::endl) via the overloaded signature.
fcf::NTest::log() << "Status: " << "Active" << std::endl;
}
int main(int a_argc, char* a_argv[]) {
bool error = false;
fcf::NTest::cmdRun(a_argc, a_argv, fcf::NTest::CRM_RUN, &error);
return error ? 1 : 0;
}
Output:
Performing the test: "LogDemo" -> "Chaining" -> "MultiTypeLog" ...
> User: 42 (JohnDoe) | Score: 95.5
> Status: Active
[SUCCESS] Test completed successfully (0.000`053`702 sec)
[SUCCESS] All tests were completed.
Tests: 1 passed, 0 failed, 0 skipped, 1 total
Duration: 0.000`053`702 sec
You need to run the program with the following parameter:
test --test-log-level inf